package com.originskyseed.platform.count.controller;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.originskyseed.platform.common.api.config.LoginConfig;
import com.originskyseed.platform.common.api.constant.RedisKeyConstans;
import com.originskyseed.platform.core.config.bean.ConfigManager;
import com.originskyseed.platform.core.redis.util.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.core.filter.helper.SingleSignOnTokenHelper;
import com.originskyseed.platform.count.i18n.CountResponseMsg;
import com.originskyseed.platform.count.model.FinancialManage;
import com.originskyseed.platform.count.service.IFinancialManageService;
import com.originskyseed.platform.count.service.IUserSalaryService;
import com.originskyseed.platform.count.vo.request.LtvRequestVO;
import com.originskyseed.platform.count.vo.request.ProfitDetailsVO;
import com.originskyseed.platform.log.model.HomePageCache;
import com.originskyseed.platform.log.service.IHomePageCacheService;
import com.originskyseed.platform.user.model.Dept;
import com.originskyseed.platform.user.model.UserInfo;
import com.originskyseed.platform.user.service.IDeptService;
import com.originskyseed.platform.user.service.IPlayerService;
import com.originskyseed.platform.user.service.IUserInfoService;

/**
 * 推广类统计 总裁、体系、分公司、部门 Controller类
 * 
 * @author Tangwanghui
 */
@Controller
@RequestMapping("/homePageCount")
@BaseLocaleResource(localeFileName = "i18n_count")
public class HomePageCountController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(HomePageCountController.class);

	@DubboReference
	private IUserSalaryService userSalaryService;

	@DubboReference
	private IDeptService deptService;

	@DubboReference
	private IUserInfoService userInfoService;

	@DubboReference
	private IPlayerService playerService;

	@DubboReference
	private IFinancialManageService financialManageService;

	@DubboReference
	private IHomePageCacheService homePageCacheService;

	/**
	 * 查询顶部数据
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectHomePage.json")
	public BaseResponseBody selectHomePage(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			Map<String, Object> map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHomePage");
			// 如果查询不到就查询数据库，并且放进redis中
			if(map==null){
				map = new HashMap<>();
				Dept dept = this.deptService.selectByPrimaryKey(deptId);
				if (dept != null) {
					List<String> list = new ArrayList<>();
					list.add(dept.getId());
					selectSonId(dept.getCode(), list);
					// 业务员数量
					List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(list);
					if (list.size() > 0 && userList.size()>0) {
						// 设备数量
						Integer equipmentNum = this.playerService.selectEquipmentNum(userList);
						// 新用户充值
						BigDecimal newUserRechargeAmount = this.playerService.selectNewUserRechargeAmount(userList);
						// 优质用户数量
						Integer highQualityUserNum = this.playerService.selectHighQualityUserNum(userList);
						// 充值用户
						Integer rechargeUserNum = this.playerService.selectRechargeUserNum(userList);
						// 累充金额
						BigDecimal rechargeUserAmount = this.playerService.selectRechargeUserAmount(userList);

						map.put("salesmenNumber", userList.size());
						map.put("equipmentNumber", equipmentNum);
						map.put("newUserRechargeAmount", newUserRechargeAmount);
						map.put("highQualityUserNum", highQualityUserNum);
						map.put("rechargeUserNum", rechargeUserNum);
						map.put("rechargeUserAmount", rechargeUserAmount);

					} else {
						map.put("salesmenNumber", 0);
						map.put("equipmentNumber", 0);
						map.put("newUserRechargeAmount", 0);
						map.put("highQualityUserNum", 0);
						map.put("rechargeUserNum", 0);
						map.put("rechargeUserAmount", 0);
					}

					// 存到redis中
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHomePage",map,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询利润趋势
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectProfitTrend.json")
	public BaseResponseBody selectProfitTrend(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			String deptId = this.getParameterString("deptId", null);
			// 类型 0日，1周，2月，3季，4年
			Integer type = this.getParameterInteger("type", null);
			// 要返回的数据
			Map<String, Object> map = null;

			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendWEEK");
			} else if(type == 2 ){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendMONTH");
			}else if(type == 3 ) {
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendQUARTER");
			}else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendYEAR");
			}


			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				List<String> columnList = new ArrayList<>();
				List<BigDecimal> rowList = new ArrayList<>();
				List<BigDecimal> row1List = new ArrayList<>();
				List<BigDecimal> row2List = new ArrayList<>();
				List<List<String>> costDetailsList = new ArrayList<>();
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<Dept> deptList = this.deptService.selectByParentCode(queryDept.getCode());
				for (Dept dept : deptList) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> salesmanIdsList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					// 用户id
					List<String> userIdsList = this.userInfoService.selectUserIdsByDeptIds(deptIds);
					// 毛利
					BigDecimal grossProfit = BigDecimal.ZERO;
					// 成本
					BigDecimal basePay = BigDecimal.ZERO;

					// 成本详细集合
					List<String> basePayList = new ArrayList<>();
					if (salesmanIdsList.size() > 0) {
						// 查询数据
						Map<String, Object> queryMap = this.playerService.selectBasePayAndGrossProfit(userIdsList,salesmanIdsList, type, 0);
						grossProfit = (BigDecimal) queryMap.get("grossProfit");
						basePay = (BigDecimal) queryMap.get("basePay");
						BigDecimal peopleBasePay = basePay;
						if (type == 0) {
							peopleBasePay = basePay.divide(new BigDecimal(30), 2, BigDecimal.ROUND_HALF_UP);
						} else if (type == 1) {
							peopleBasePay = basePay.divide(new BigDecimal(4), 2, BigDecimal.ROUND_HALF_UP);
						} else if (type == 3) {
							peopleBasePay = basePay.multiply(new BigDecimal(4));
						} else if (type == 4) {
							peopleBasePay = basePay.multiply(new BigDecimal(12));
						}
						basePayList.add("人力成本："+peopleBasePay);
					}

					// 计算成本
					List<String> deptIdList = new ArrayList<>();
					deptIdList.add(dept.getId());
					selectSonIdCompanyDept(dept.getCode(), deptIdList);
					FinancialManage query = new FinancialManage();
					query.setList(deptIdList);
					query.setType(1);
					query.setStartTime(getMonthFirstDay());
					List<FinancialManage> financialManageList = this.financialManageService.selectList(query);
					for (FinancialManage financialManage : financialManageList) {
						basePay = basePay.add(financialManage.getAmount());
					}
					if (type == 0) {
						basePay = basePay.divide(new BigDecimal(30), 2, BigDecimal.ROUND_HALF_UP);
					} else if (type == 1) {
						basePay = basePay.divide(new BigDecimal(4), 2, BigDecimal.ROUND_HALF_UP);
					} else if (type == 3) {
						basePay = basePay.multiply(new BigDecimal(4));
					} else if (type == 4) {
						basePay = basePay.multiply(new BigDecimal(12));
					}

					// 查询成本详细
					Map<String,Object> queryMap = new HashMap<>();
					queryMap.put("list",deptIdList);
					queryMap.put("type",1);
					queryMap.put("startTime",getMonthFirstDay());
					List<Map<String,Object>> mapList = this.financialManageService.selectUserBasePay(queryMap);
					for (Map<String,Object> objMap:mapList) {
						BigDecimal amount = (BigDecimal) objMap.get("amount");
						if (type == 0) {
							amount = amount.divide(new BigDecimal(30), 2, BigDecimal.ROUND_HALF_UP);
						} else if (type == 1) {
							amount = amount.divide(new BigDecimal(4), 2, BigDecimal.ROUND_HALF_UP);
						} else if (type == 3) {
							amount = amount.multiply(new BigDecimal(4));
						} else if (type == 4) {
							amount = amount.multiply(new BigDecimal(12));
						}
						basePayList.add(objMap.get("name")+":"+amount);
					}

					costDetailsList.add(basePayList);
					rowList.add(basePay);
					row1List.add(grossProfit.setScale(2, BigDecimal.ROUND_HALF_UP));
					row2List.add(grossProfit.subtract(basePay).setScale(2, BigDecimal.ROUND_HALF_UP));
					columnList.add(dept.getName());
				}
				map.put("columnList", columnList);
				map.put("basePayList", rowList);
				map.put("grossProfitList", row1List);
				map.put("profitList", row2List);
				map.put("costDetailsList",costDetailsList);

				// 存进redis中
				if(type==0){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendDAY",map,getCacheInvalidTime());
				} else if (type==1){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendWEEK",map,getCacheInvalidTime());
				} else if(type == 2 ){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendMONTH",map,getCacheInvalidTime());
				}else if(type == 3 ) {
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendQUARTER",map,getCacheInvalidTime());
				}else{
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectProfitTrendYEAR",map,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询LTV
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectUserLTV.json")
	public BaseResponseBody selectUserLTV(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的对象
			BasePage<Map> resultPage = new BasePage();

			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);

			// 参数
			LtvRequestVO requestVO = this.getParameterBean(LtvRequestVO.class);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}

			if (userInfo != null) {
				// 分页查询
				BasePage<Dept> page = new BasePage<Dept>(requestVO.getPageNo(), requestVO.getPageSize());
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				requestVO.setParentCode(queryDept.getCode());
				// 查询数据
				page = this.deptService.selectByParentCodeAndName(requestVO.toMap(), page);

				// 封装集合
				List<Map> list = new ArrayList<>();
				for (Dept dept : page.getResults()) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					// 查询数据
					Map<String, Object> map = new HashMap<>();
					if (userList.size() > 0) {
						map = this.playerService.selectUserLtv(userList, 0);
					} else {
						map.put("firstDayLtv", BigDecimal.ZERO);
						map.put("twoDayLtv", BigDecimal.ZERO);
						map.put("threeDayLtv", BigDecimal.ZERO);
						map.put("sevenDayLtv", BigDecimal.ZERO);
						map.put("fifteenDayLtv", BigDecimal.ZERO);
						map.put("thirtyDayLtv", BigDecimal.ZERO);
						map.put("sixtyDayLtv", BigDecimal.ZERO);
					}
					map.put("deptName", dept.getName());
					list.add(map);
				}

				// 分页查询
				resultPage = new BasePage<Map>(requestVO.getPageNo(), requestVO.getPageSize());
				resultPage.setResults(list);
				resultPage.setTotalRecord(page.getTotalRecord());
				resultPage.setTotalPage(page.getTotalPage());
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultPage);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询利润明细
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectProfitDetails.json")
	public BaseResponseBody selectProfitDetails(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的对象
			BasePage<Map> resultPage = new BasePage();

			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);

			// 参数
			ProfitDetailsVO requestVO = this.getParameterBean(ProfitDetailsVO.class);
			String date = this.getParameterString("date", null);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			if (date == null) {
				date = getToday();
			}

			if (userInfo != null) {
				// 分页查询
				BasePage<Dept> page = new BasePage<Dept>(requestVO.getPageNo(), requestVO.getPageSize());
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				requestVO.setParentCode(queryDept.getCode());
				// 查询数据
				BasePage<Dept> basePage = this.deptService.selectByParentCodeAndName(requestVO.toMap(), page);

				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				// 封装集合
				List<Map> list = new ArrayList<>();
				for (Dept dept : basePage.getResults()) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> salesmanIdList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					// 用户id
					List<String> userIdsList = this.userInfoService.selectUserIdsByDeptIds(deptIds);
					// 查询数据
					Map<String, Object> map = new HashMap<>();

					// 查询成本
					BigDecimal basePay = BigDecimal.ZERO;
					if (salesmanIdList.size() > 0) {
						map = this.playerService.selectProfitDetails(date,userIdsList, salesmanIdList, 0);
						basePay = (BigDecimal) map.get("basePay");
					} else {
						map.put("grossProfit", BigDecimal.ZERO);
						map.put("profit", BigDecimal.ZERO);
					}

					//查询财务
					List<String> deptIdList = new ArrayList<>();
					deptIdList.add(dept.getId());
					selectSonIdCompanyDept(dept.getCode(), deptIdList);
					FinancialManage query = new FinancialManage();
					query.setList(deptIdList);
					query.setType(1);
					if (StringUtils.isNotBlank(date)) {
						query.setStartTime(sdf.parse(date.substring(0, 7) + "-01 00:00:00"));
					} else {
						query.setStartTime(getMonthFirstDay());
					}
					List<FinancialManage> financialManageList = this.financialManageService.selectList(query);
					for (FinancialManage financialManage : financialManageList) {
						basePay = basePay.add(financialManage.getAmount());
					}
					basePay = basePay.divide(new BigDecimal(30), 2, BigDecimal.ROUND_HALF_UP);

					BigDecimal grossProfit = (BigDecimal) map.get("grossProfit");
					map.put("basePay", basePay);
					map.put("profit", grossProfit.subtract(basePay));
					map.put("date", date);
					map.put("name", dept.getName());
					list.add(map);
				}

				// 分页查询
				resultPage = new BasePage<Map>(requestVO.getPageNo(), requestVO.getPageSize());
				resultPage.setResults(list);
				resultPage.setTotalRecord(page.getTotalRecord());
				resultPage.setTotalPage(page.getTotalPage());
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultPage);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询KPI
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectKPI.json")
	public BaseResponseBody selectKPI(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			String deptId = this.getParameterString("deptId", null);
			// 类型 0日，1周，2月，3季，4年
			Integer type = this.getParameterInteger("type", null);
			// 要返回的数据
			Map<String, Object> map = null;

			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIWEEK");
			} else if(type == 2 ){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIMONTH");
			}else if(type == 3 ) {
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIQUARTER");
			}else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIYEAR");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				List<String> columnList = new ArrayList<>();
				List<BigDecimal> rowList = new ArrayList<>();
				List<BigDecimal> row1List = new ArrayList<>();
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<Dept> deptList = this.deptService.selectByParentCode(queryDept.getCode());
				for (Dept dept : deptList) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);

					// 查询营收值
					BigDecimal revenueValue;
					if (userList.size() > 0) {
						revenueValue = this.playerService.selectRevenueValue(type, userList, 0);
					} else {
						revenueValue = BigDecimal.ZERO;
					}

					BigDecimal kpi = BigDecimal.ZERO;
					FinancialManage query = new FinancialManage();
					query.setObjId(dept.getId());
					query.setType(2);
					query.setStartTime(getMonthFirstDay());
					List<FinancialManage> financialManageList = this.financialManageService.selectList(query);
					for (FinancialManage financialManage : financialManageList) {
						kpi = kpi.add(financialManage.getAmount());
					}

					if (type == 0) {
						kpi = kpi.divide(new BigDecimal(30), 2, BigDecimal.ROUND_HALF_UP);
					} else if (type == 1) {
						kpi = kpi.divide(new BigDecimal(4), 2, BigDecimal.ROUND_HALF_UP);
					} else if (type == 3) {
						kpi = kpi.multiply(new BigDecimal(4));
					} else if (type == 4) {
						kpi = kpi.multiply(new BigDecimal(12));
					}
					rowList.add(revenueValue);
					row1List.add(kpi);
					columnList.add(dept.getName());
				}
				map.put("columnList", columnList);
				map.put("kipCompleteList", rowList);
				map.put("kipTargetList", row1List);

				// 存进redis中
				if(type==0){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIDAY",map,getCacheInvalidTime());
				} else if (type==1){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIWEEK",map,getCacheInvalidTime());
				} else if(type == 2 ){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIMONTH",map,getCacheInvalidTime());
				}else if(type == 3 ) {
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIQUARTER",map,getCacheInvalidTime());
				}else{
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectKPIYEAR",map,getCacheInvalidTime());
				}
			}

			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询平均产值
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAverageOutputValue.json")
	public BaseResponseBody selectAverageOutputValue(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId", null);
			// 类型 0日，2月
			Integer type = this.getParameterInteger("type", null);
			// 要返回的数据
			Map<String, Object> resultMap = null;

			// 从redis中查询是否存在
			if(type==0){
				resultMap = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectAverageOutputValueDAY");
			}else {
				resultMap =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectAverageOutputValueMONTH");
			}

			// 如果不存在则直接查询，并且放进redis中
			if(resultMap==null){
				resultMap = new HashMap<>();
				List<String> columnList = new ArrayList<>();
				List<BigDecimal> rowList = new ArrayList<>();
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<Dept> deptList = this.deptService.selectByParentCode(queryDept.getCode());
				for (Dept dept : deptList) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					// 查询营收值
					BigDecimal revenueValue;
					BigDecimal averageRevenueValue;
					if (userList.size() > 0) {
						revenueValue = this.playerService.selectRevenueValue(type, userList, 0);
						averageRevenueValue = revenueValue.divide(new BigDecimal(userList.size()), 2, RoundingMode.HALF_UP);
					} else {
						averageRevenueValue = BigDecimal.ZERO;
					}
					rowList.add(averageRevenueValue);
					columnList.add(dept.getName());
				}
				resultMap.put("columnList", columnList);
				resultMap.put("rowList", rowList);

				// 存进redis中
				if(type==0){
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectAverageOutputValueDAY",resultMap,getCacheInvalidTime());
				}else {
					RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectAverageOutputValueMONTH",resultMap,getCacheInvalidTime());
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultMap);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询优质用户
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectHighQualityUsers.json")
	public BaseResponseBody selectHighQualityUsers(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 获取参数
			String deptId = this.getParameterString("deptId", null);

			// 从redis中查询是否存在
			Map<String, Object> map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsers");

			// 不存在则直接查询数据库
			if(map==null){
				map = new HashMap<>();
				UserInfo userInfo = this.userInfoService.selectByPrimaryKey(deptId);
				// 业务员查询
				if (userInfo != null) {
					List<String> userList = new ArrayList<>();
					userList.add(userInfo.getOtherAccount());
					map = this.playerService.selectHighQualityUsers(userList, 0);
				} else {
					// 获取下级
					Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
					List<String> userList = new ArrayList<>();
					if (queryDept != null) {
						List<String> deptIds = new ArrayList<>();
						deptIds.add(deptId);
						this.selectSonId(queryDept.getCode(), deptIds);
						userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					}
					if (userList.size() > 0) {
						map = this.playerService.selectHighQualityUsers(userList, 0);
					}
				}

				// 存进redis中
				RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectHighQualityUsers",map,getCacheInvalidTime());
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询新充金额
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectNewChargeAmount.json")
	public BaseResponseBody selectNewChargeAmount(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId", null);
			// 参数
			Integer type = this.getParameterInteger("type", null);
			// 要返回的数据
			Map<String, Object> map = null;

			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewChargeAmountDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewChargeAmountWEEK");
			} else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewChargeAmountMONTH");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(queryDept.getId());
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
				if (userList.size() > 0) {
					map = this.playerService.selectNewChargeAmount(type, userList, 0, 0);

					// 存进redis里面
					if(type==0){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewChargeAmountDAY",map,getCacheInvalidTime());
					} else if (type==1){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewChargeAmountWEEK",map,getCacheInvalidTime());
					} else{
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectNewChargeAmountMONTH",map,getCacheInvalidTime());
					}
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询累充金额
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectTiredAndFullAmount.json")
	public BaseResponseBody selectTiredAndFullAmount(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId", null);
			// 参数
			Integer type = this.getParameterInteger("type", null);
			// 要返回的数据
			Map<String, Object> map = null;

			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountWEEK");
			} else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountMONTH");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(queryDept.getId());
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
				if (userList.size() > 0) {
					map = this.playerService.selectNewChargeAmount(type, userList, 1, 0);
					// 存进redis里面
					if(type==0){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountDAY",map,getCacheInvalidTime());
					} else if (type==1){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountWEEK",map,getCacheInvalidTime());
					} else{
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountMONTH",map,getCacheInvalidTime());
					}
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询充值分析
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectRechargeAnalysis.json")
	public BaseResponseBody selectRechargeAnalysis(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId", null);
			// 参数
			Integer type = this.getParameterInteger("type", null);
			// 要返回的数据
			Map<String, Object> map = null;

			// 从redis中查询是否存在
			if(type==0){
				map = (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountDAY");
			} else if (type==1){
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountWEEK");
			} else{
				map =  (Map<String, Object>)RedisUtil.getInstance().getForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountMONTH");
			}

			// 如果redis里面为空，则查询数据库，并且存进redis里面
			if(map==null){
				map = new HashMap<>();
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(queryDept.getId());
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
				if (userList.size() > 0) {
					map = this.playerService.selectRechargeAnalysis(type, userList, 0);

					// 存进redis里面
					if(type==0){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountDAY",map,getCacheInvalidTime());
					} else if (type==1){
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountWEEK",map,getCacheInvalidTime());
					} else{
						RedisUtil.getInstance().setForObject(RedisKeyConstans.HOME_PAGE_KEY+deptId+"selectTiredAndFullAmountMONTH",map,getCacheInvalidTime());
					}
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询任务发布数量
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectTaskReleaseNums.json")
	public BaseResponseBody selectTaskReleaseNums(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的数据
			Map<String, Object> map = new HashMap<>();
			List<String> columnList = new ArrayList<>();
			List<Integer> rowList = new ArrayList<>();
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			if (userInfo != null) {
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<Dept> deptList = this.deptService.selectByParentCode(queryDept.getCode());
				for (Dept dept : deptList) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectUserIdsByDeptIds(deptIds);
					// 查询任务发布数量
					Integer number;
					if (userList.size() > 0) {
						number = this.playerService.selectTaskReleaseNums(userList);
					} else {
						number = 0;
					}
					rowList.add(number);
					columnList.add(dept.getName());
				}
			}
			map.put("columnList", columnList);
			map.put("rowList", rowList);
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询派单任务
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAssignmentTask.json")
	public BaseResponseBody selectAssignmentTask(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的数据
			Map<String, Object> map = new HashMap<>();
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			// 参数
			Integer type = this.getParameterInteger("type", null);
			if (userInfo != null) {
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(deptId);
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectUserIdsByDeptIds(deptIds);
				if (userList.size() > 0) {
					map = this.playerService.selectAssignmentTask(type, userList);
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询业务员数量
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectSalesmenNumber.json")
	public BaseResponseBody selectSalesmenNumber(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的数据
			Map<String, Object> map = new HashMap<>();
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			// 参数
			Integer type = this.getParameterInteger("type", null);
			//if (userInfo != null) {
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(queryDept.getId());
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectSalesmanUserIdsByDeptIds(deptIds);
				if (userList.size() > 0) {
					map = this.playerService.selectAddEquipmentNumber(type, userList, 5);
				}
		//	}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询业务员数量明细
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectSalesmenDetailed.json")
	public BaseResponseBody selectSalesmenDetailed(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的对象
			BasePage<Map> resultPage = new BasePage();

			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);

			// 参数
			ProfitDetailsVO requestVO = this.getParameterBean(ProfitDetailsVO.class);
			String date = this.getParameterString("date", null);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			if (date == null) {
				date = getToday();
			}

			if (userInfo != null) {
				// 分页查询
				BasePage<Dept> page = new BasePage<Dept>(requestVO.getPageNo(), requestVO.getPageSize());
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				requestVO.setParentCode(queryDept.getCode());
				// 查询数据
				BasePage<Dept> basePage = this.deptService.selectByParentCodeAndName(requestVO.toMap(), page);

				// 封装集合
				List<Map> list = new ArrayList<>();
				for (Dept dept : basePage.getResults()) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectSalesmanUserIdsByDeptIds(deptIds);
					// 查询数据
					Map<String, Object> map = new HashMap<>();
					if (userList.size() > 0) {
						// 查询数据
						map = this.playerService.selectAddEquipmentNumberDetailed(date, userList, 5);
					} else {
						map.put("number", 0);
						map.put("lastNumber", 0);
						map.put("add", 0);
					}

					map.put("date", date);
					map.put("name", dept.getName());
					list.add(map);
				}

				// 分页查询
				resultPage = new BasePage<Map>(requestVO.getPageNo(), requestVO.getPageSize());
				resultPage.setResults(list);
				resultPage.setTotalRecord(page.getTotalRecord());
				resultPage.setTotalPage(page.getTotalPage());
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultPage);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询新增设备数量
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAddEquipmentNumber.json")
	public BaseResponseBody selectAddEquipmentNumber(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的数据
			Map<String, Object> map = new HashMap<>();
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			// 参数
			Integer type = this.getParameterInteger("type", null);
			if (userInfo != null) {
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(queryDept.getId());
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
				if(userList.size()>0){
					map = this.playerService.selectAddEquipmentNumber(type, userList, 0);
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询新增设备数量明细
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAddEquipmentNumberDetailed.json")
	public BaseResponseBody selectAddEquipmentNumberDetailed(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的对象
			BasePage<Map> resultPage = new BasePage();

			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);

			// 参数
			ProfitDetailsVO requestVO = this.getParameterBean(ProfitDetailsVO.class);
			String date = this.getParameterString("date", null);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			if (date == null) {
				date = getToday();
			}

			if (userInfo != null) {
				// 分页查询
				BasePage<Dept> page = new BasePage<Dept>(requestVO.getPageNo(), requestVO.getPageSize());
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				requestVO.setParentCode(queryDept.getCode());
				// 查询数据
				page = this.deptService.selectByParentCodeAndName(requestVO.toMap(), page);

				// 封装集合
				List<Map> list = new ArrayList<>();
				for (Dept dept : page.getResults()) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					// 查询数据
					Map<String, Object> map = new HashMap<>();
					if(userList.size()>0){
						map = this.playerService.selectAddEquipmentNumberDetailed(date, userList, 0);
					}
					map.put("date", date);
					map.put("name", dept.getName());
					list.add(map);
				}

				// 分页查询
				resultPage = new BasePage<Map>(requestVO.getPageNo(), requestVO.getPageSize());
				resultPage.setResults(list);
				resultPage.setTotalRecord(page.getTotalRecord());
				resultPage.setTotalPage(page.getTotalPage());
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultPage);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询新用户充值数量
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectNewUserRecharge.json")
	public BaseResponseBody selectNewUserRecharge(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的数据
			Map<String, Object> map = new HashMap<>();
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			// 参数
			Integer type = this.getParameterInteger("type", null);
			if (userInfo != null) {
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(queryDept.getId());
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
				if (userList.size()>0){
					map = this.playerService.selectAddEquipmentNumber(type, userList, 1);
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询新用户充值明细
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectNewUserRechargeDetailed.json")
	public BaseResponseBody selectNewUserRechargeDetailed(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的对象
			BasePage<Map> resultPage = new BasePage();

			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);

			// 参数
			ProfitDetailsVO requestVO = this.getParameterBean(ProfitDetailsVO.class);
			String date = this.getParameterString("date", null);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			if (date == null) {
				date = getToday();
			}

			if (userInfo != null) {
				// 分页查询
				BasePage<Dept> page = new BasePage<Dept>(requestVO.getPageNo(), requestVO.getPageSize());
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				requestVO.setParentCode(queryDept.getCode());
				// 查询数据
				BasePage<Dept> basePage = this.deptService.selectByParentCodeAndName(requestVO.toMap(), page);

				// 封装集合
				List<Map> list = new ArrayList<>();
				for (Dept dept : basePage.getResults()) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					// 查询数据
					Map<String, Object> map = new HashMap<>();
					if(userList.size()>0){
						 map = this.playerService.selectAddEquipmentNumberDetailed(date, userList, 1);
					}

					map.put("date", date);
					map.put("name", dept.getName());
					list.add(map);
				}

				// 分页查询
				resultPage = new BasePage<Map>(requestVO.getPageNo(), requestVO.getPageSize());
				resultPage.setResults(list);
				resultPage.setTotalRecord(page.getTotalRecord());
				resultPage.setTotalPage(page.getTotalPage());
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultPage);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询优质用户数量
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectHighQualityUser.json")
	public BaseResponseBody selectHighQualityUser(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的数据
			Map<String, Object> map = new HashMap<>();
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			// 参数
			Integer type = this.getParameterInteger("type", null);
			if (userInfo != null) {
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(queryDept.getId());
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
				if (userList.size()>0){
					map = this.playerService.selectAddEquipmentNumber(type, userList, 2);
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询优质用户数量明细
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectHighQualityUserCount.json")
	public BaseResponseBody selectHighQualityUserCount(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的对象
			BasePage<Map> resultPage = new BasePage();

			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);

			// 参数
			ProfitDetailsVO requestVO = this.getParameterBean(ProfitDetailsVO.class);
			String date = this.getParameterString("date", null);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			if (date == null) {
				date = getToday();
			}

			if (userInfo != null) {
				// 分页查询
				BasePage<Dept> page = new BasePage<Dept>(requestVO.getPageNo(), requestVO.getPageSize());
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				requestVO.setParentCode(queryDept.getCode());
				// 查询数据
				BasePage<Dept> basePage = this.deptService.selectByParentCodeAndName(requestVO.toMap(), page);

				// 封装集合
				List<Map> list = new ArrayList<>();
				for (Dept dept : basePage.getResults()) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					// 查询数据
					Map<String, Object> map = new HashMap<>();
					if(userList.size()>0){
						map = this.playerService.selectAddEquipmentNumberDetailed(date, userList, 2);
					}
					map.put("date", date);
					map.put("name", dept.getName());
					list.add(map);
				}

				// 分页查询
				resultPage = new BasePage<Map>(requestVO.getPageNo(), requestVO.getPageSize());
				resultPage.setResults(list);
				resultPage.setTotalRecord(page.getTotalRecord());
				resultPage.setTotalPage(page.getTotalPage());
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultPage);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询充值用户数量
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectRechargeUser.json")
	public BaseResponseBody selectRechargeUser(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的数据
			Map<String, Object> map = new HashMap<>();
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			// 参数
			Integer type = this.getParameterInteger("type", null);
			if (userInfo != null) {
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(queryDept.getId());
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
				if (userList.size()>0){
					map = this.playerService.selectAddEquipmentNumber(type, userList, 3);
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询充值用户数量明细
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectRechargeUserCount.json")
	public BaseResponseBody selectRechargeUserCount(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的对象
			BasePage<Map> resultPage = new BasePage();

			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);

			// 参数
			ProfitDetailsVO requestVO = this.getParameterBean(ProfitDetailsVO.class);
			String date = this.getParameterString("date", null);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			if (date == null) {
				date = getToday();
			}

			if (userInfo != null) {
				// 分页查询
				BasePage<Dept> page = new BasePage<Dept>(requestVO.getPageNo(), requestVO.getPageSize());
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				requestVO.setParentCode(queryDept.getCode());
				// 查询数据
				BasePage<Dept> basePage = this.deptService.selectByParentCodeAndName(requestVO.toMap(), page);

				// 封装集合
				List<Map> list = new ArrayList<>();
				for (Dept dept : basePage.getResults()) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					// 查询数据
					Map<String, Object> map = new HashMap<>();
					if(userList.size()>0){
						map = this.playerService.selectAddEquipmentNumberDetailed(date, userList, 3);
					}
					map.put("date", date);
					map.put("name", dept.getName());
					list.add(map);
				}

				// 分页查询
				resultPage = new BasePage<Map>(requestVO.getPageNo(), requestVO.getPageSize());
				resultPage.setResults(list);
				resultPage.setTotalRecord(page.getTotalRecord());
				resultPage.setTotalPage(page.getTotalPage());
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultPage);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询累计充值额度
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectTiredAndFull.json")
	public BaseResponseBody selectTiredAndFull(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的数据
			Map<String, Object> map = new HashMap<>();
			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			// 参数
			Integer type = this.getParameterInteger("type", null);
			if (userInfo != null) {
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				List<String> deptIds = new ArrayList<>();
				deptIds.add(queryDept.getId());
				this.selectSonId(queryDept.getCode(), deptIds);
				List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
				if (userList.size()>0){
					map = this.playerService.selectAddEquipmentNumber(type, userList, 4);
				}
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), map);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 查询累计充值额度明细
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectTiredAndFullCount.json")
	public BaseResponseBody selectTiredAndFullCount(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 返回的对象
			BasePage<Map> resultPage = new BasePage();

			// 当前用户信息
			UserInfo userInfo = SingleSignOnTokenHelper.getCurrentUserInfo(UserInfo.class);

			// 参数
			ProfitDetailsVO requestVO = this.getParameterBean(ProfitDetailsVO.class);
			String date = this.getParameterString("date", null);
			String deptId = this.getParameterString("deptId", null);
			if (deptId == null) {
				deptId = userInfo.getDeptId();
			}
			if (date == null) {
				date = getToday();
			}

			if (userInfo != null) {
				// 分页查询
				BasePage<Dept> page = new BasePage<Dept>(requestVO.getPageNo(), requestVO.getPageSize());
				// 获取下级
				Dept queryDept = this.deptService.selectByPrimaryKey(deptId);
				requestVO.setParentCode(queryDept.getCode());
				// 查询数据
				BasePage<Dept> basePage = this.deptService.selectByParentCodeAndName(requestVO.toMap(), page);

				// 封装集合
				List<Map> list = new ArrayList<>();
				for (Dept dept : basePage.getResults()) {
					// 所有下级部门id
					List<String> deptIds = new ArrayList<>();
					deptIds.add(dept.getId());
					this.selectSonId(dept.getCode(), deptIds);
					// 业务员id
					List<String> userList = this.userInfoService.selectSalesmanIdsByDeptIds(deptIds);
					// 查询数据
					Map<String, Object> map = new HashMap<>();
					if(userList.size()>0){
						map = this.playerService.selectAddEquipmentNumberDetailed(date, userList, 4);
					}
					map.put("date", date);
					map.put("name", dept.getName());
					list.add(map);
				}

				// 分页查询
				resultPage = new BasePage<Map>(requestVO.getPageNo(), requestVO.getPageSize());
				resultPage.setResults(list);
				resultPage.setTotalRecord(page.getTotalRecord());
				resultPage.setTotalPage(page.getTotalPage());
			}
			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_SUCCESS.getMsg()), resultPage);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_SELECT_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}


	/**
	 * 查询累计充值额度明细
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/deleteHomePageCache.json")
	public BaseResponseBody deleteHomePageCache(HttpServletRequest request) {
		BaseResponseBody result = null;
		try {
			// 部门id
			String deptId = this.getParameterString("deptId",null);
			if(deptId==null){
				RedisUtil.getInstance().deleteByPattern(RedisKeyConstans.HOME_PAGE_KEY+"*");
			}else {
				RedisUtil.getInstance().deleteByPattern(RedisKeyConstans.HOME_PAGE_KEY+deptId+"*");
			}


			result = new BaseResponseBody(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_DELETE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CountResponseMsg.DATA_DELETE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}


	/**
	 * 查询组织架构接口
	 * 
	 * @param code
	 * @param list
	 * @throws Exception
	 */
	private void selectGroupId(String code, List<String> list) throws Exception {
		List<Dept> deptList = this.deptService.selectByParentCode(code);
		if (deptList != null) {
			for (Dept dept1 : deptList) {
				if (dept1.getType() == 5) {
					list.add(dept1.getId());
				}
				selectGroupId(dept1.getCode(), list);
			}
		}
	}

	/**
	 * 查询下级分公司或者部门
	 * 
	 * @param code
	 * @param list
	 * @throws Exception
	 */
	private void selectSonIdCompanyDept(String code, List<String> list) throws Exception {
		List<Dept> deptList = this.deptService.selectByParentCode(code);
		if (deptList != null) {
			for (Dept dept1 : deptList) {
				if (dept1.getType() == 0 || dept1.getType() == 1 || dept1.getType() == 2) {
					list.add(dept1.getId());
				}
				selectSonIdCompanyDept(dept1.getCode(), list);
			}
		}
	}

	/**
	 * 查询组织架构接口
	 * 
	 * @param code
	 * @param list
	 * @throws Exception
	 */
	private void selectSonId(String code, List<String> list) throws Exception {
		List<Dept> deptList = this.deptService.selectByParentCode(code);
		if (deptList != null) {
			for (Dept dept1 : deptList) {
				list.add(dept1.getId());
				selectSonId(dept1.getCode(), list);
			}
		}
	}

	/**
	 * 查询今日日期
	 * 
	 * @return
	 * @throws Exception
	 */
	private String getToday() throws Exception {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(new Date());
	}

	/**
	 * 查询本月第一天
	 * 
	 * @return
	 * @throws Exception
	 */
	private Date getMonthFirstDay() throws Exception {
		Calendar c = Calendar.getInstance();
		try {
			c.set(Calendar.DATE, 1);
			c.set(Calendar.HOUR_OF_DAY, 0);
			c.set(Calendar.MINUTE, 0);
			c.set(Calendar.SECOND, 0);
			c.set(Calendar.MILLISECOND, 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return c.getTime();
	}

	/**
	 * 获取失效时间
	 * @return
	 */
	private long getCacheInvalidTime(){
		LoginConfig loginConfig = ConfigManager.getInstance().parseObject(LoginConfig.class);
		long timeOut = 7200000;
		if(loginConfig!=null && loginConfig.getCacheInvalidTime()!=null){
			timeOut = loginConfig.getCacheInvalidTime()*60*1000;
		}
		return timeOut;
	}
}